package org.example.myleet.p807;

/**
 * 思路：贪心
 */
public class Solution {
    public int maxIncreaseKeepingSkyline(int[][] grid) {
        int m = grid.length, n = grid[0].length;
        int[] maxHorizontal = new int[m];
        int[] maxVertical = new int[n];
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                maxHorizontal[i] = Math.max(maxHorizontal[i], grid[i][j]);
                maxVertical[j] = Math.max(maxVertical[j], grid[i][j]);
            }
        }
        int sum = 0;
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                int maxHeight = Math.min(maxHorizontal[i], maxVertical[j]);
                sum += maxHeight - grid[i][j];
            }
        }
        return sum;
    }
}
